#ifndef MANAGERSWIN_H
#define MANAGERSWIN_H

#include <QMainWindow>
#include <QStandardItemModel>
#include <QMessageBox>
#include <QString>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QPushButton>

namespace Ui {
class managerswin;
}

class managerswin : public QMainWindow
{
    Q_OBJECT

public:
    explicit managerswin(QWidget *parent = nullptr);
    ~managerswin();

    // Set manager info
    void setManagerInfo(const QString &username);

private slots:
    // Main list buttons
    void on_ListPackageBtn_clicked();
    void on_ListOrderBtn_clicked();
    void on_ListUserBtn_clicked();

    // User management
    void on_UserSearchBtn_clicked();
    void on_AddUserBtn_clicked();

    // Package management
    void on_InputStorageBtn_clicked();
    void on_OutputStorageBtn_clicked();

    // Shipping management
    void on_PackageSearchBtn_clicked();
    void on_PriceChangeBtn_clicked();
    void on_DestinationChangeBtn_clicked();

    // Notification center
    void on_ViewNotificationBtn_clicked();
    void on_SendNotificationBtn_clicked();

    // Operation history
    void on_operationhisButton_clicked();

    // Coupon management
    void on_IssueCouponBtn_clicked();
    void on_ViewAndChangeCouponBtn_clicked();

    // Order management
    void on_SearchOrderBtn_clicked();
    void on_ChangeOrderBtn_clicked();

    // Pagination slots
    void onNextPageClicked();
    void onPrevPageClicked();
    void onPageNumberChanged(int page);

private:
    Ui::managerswin *ui;
    QStandardItemModel *model;
    QSqlDatabase sqlDb;

    // Pagination properties
    int currentPage;
    int pageSize;
    int totalItems;
    QString currentTable;

    // Helper functions to populate the table
    void loadPackagesIntoTable();
    void loadOrdersIntoTable();
    void loadUsersIntoTable();

    // Pagination helpers
    void setupPagination();
    void updatePagination();
    int calculateTotalPages();
    void updatePageNavigationStatus();

    // Initialize database connection
    bool initDatabase();
};

#endif // MANAGERSWIN_H
